@extends('layouts.front')

@section('content')
@push('styles')
@endpush

<div class="bank-card">
    <form id="form">
        <div class="weui-cells">
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <input class="weui-input" type="email" v-model="account" required  placeholder="设置后台登录账号(邮箱)">
                </div>
            </div>

            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <input class="weui-input" v-model="password" type="text" required  placeholder="设置后台登录密码">
                </div>
            </div>

        </div>
        <div class="cert-action">
            <a @click="createAccount" href="javascript:;" class="weui-btn weui-btn_primary">提交</a>
        </div>
    </form>
</div>

@section('tabbar')
@endsection

@push('scripts')
<script>
var account = "@php if($manager->email) echo $manager->email; @endphp";

var vm = new Vue({
    el: '#app',
    data: {
        account: account,
        password: null
    },
    methods: {
        createAccount: function() {
            var self = this;
            weui.form.validate('#form', function (error) {
                if (!error) {
                    var loading = weui.loading('提交中...');
                    $.ajax({
                        type: 'POST',
                        url: "{{ route('member.accountStore') }}",
                        dataType: 'json',
                        data: {
                            email: self.account,
                            password: self.password
                        },
                        success: function(res) {
                            loading.hide();
                            if (res.status === 'success') {
                                weui.toast('设置成功', 3000);
                            } else {
                                weui.topTips(res.message, 3000);
                            }
                        }
                    });
                }
                // return true; // 当return true时，不会显示错误
            });
        }
    }
});
</script>
@endpush
@endsection
